﻿// Decompiled with JetBrains decompiler
// Type: YJM_PTO.Form4
// Assembly: YJM_PTO, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 17EE8669-AD07-48C9-A340-87C7401F98C3
// Assembly location: C:\Users\Administrator\Desktop\bin\YJM_PTO.exe

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Management;
using System.Text;
using System.Windows.Forms;


namespace YJM_PTO
{
    public class Form4 : Form
    {
        private IContainer components = (IContainer)null;
        private Label label3;
        private TextBox txtCodeInfo;
        private Button SelectFile;
        private Label label1;
        private TextBox txtZCFilePath;
        private Button btnUpdateCus;
        private Label label2;
        private Label label4;
        private Label lblzc;
        private Label label5;

        public static string zc = "zkzc566zhjuingamggfttenn";

        public Form4() => this.InitializeComponent();

        private void SelectFile_Click(object sender, EventArgs e)
        {
            string str = string.Empty;
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "Files(*.zz) | *.zz";
            OpenFileDialog openFileDialog2 = openFileDialog1;
            if (openFileDialog2.ShowDialog() == DialogResult.OK)
                str = openFileDialog2.FileName;
            this.txtZCFilePath.Text = str;
        }

        private void btnUpdateCus_Click(object sender, EventArgs e)
        {
            string fileName = this.txtZCFilePath.Text.Trim();
            if (string.IsNullOrEmpty(fileName))
            {
                int num1 = (int)MessageBox.Show("请确保文件选择正确：注册文件路径不能为空！！");
            }
            else
            {
                string str = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\sys.zk";
                if (File.Exists(str))
                    File.Delete(str);
                new FileInfo(fileName).CopyTo(str, true);
                this.GetNowZC();
                int num2 = (int)MessageBox.Show("软件注册成功！！");
            }
        }

        public static string GetSerialNumber()
        {
            List<string> stringList = new List<string>();
            try
            {
                foreach (ManagementBaseObject managementBaseObject in new ManagementObjectSearcher("SELECT * FROM Win32_PhysicalMedia").Get())
                {
                    string str = managementBaseObject["SerialNumber"].ToString().Trim();
                    stringList.Add(str);
                }
            }
            catch (Exception ex)
            {
                stringList.Add(zc);
            }
            if (stringList.Count==0) {
                stringList.Add(zc);
            }
            //var dele = new List<string>();
            //for (int i = 0; i < stringList.Count; i++)
            //{
            //    string cleanedString = stringList[i].Replace("\u001f", string.Empty);
            //    if (string.IsNullOrEmpty(cleanedString) || string.IsNullOrWhiteSpace(cleanedString))
            //    {
            //        dele.Add(stringList[i]);
            //    }
            //}
            //foreach (var v in dele)
            //{
            //    stringList.Remove(v);
            //}
            //if (stringList.Count == 0)
            //{
            //    stringList.Add("zkzc566zhjuingamggfttenn");
            //}
            stringList.Sort((s1, s2) => s2.Length.CompareTo(s1.Length));
            return stringList[0];
        }

        private void Form4_Load(object sender, EventArgs e)
        {
            this.txtCodeInfo.Text = Form4.GetSerialNumber();
            this.GetNowZC();

            //this.txtCodeInfo.Text = "zkzc" + DateTime.Now.ToString("fffssmmHHddMM");
        }

        private void txtCodeInfo_DoubleClick(object sender, EventArgs e)
        {
            if (this.txtCodeInfo.Text != "")
            {
                Clipboard.SetDataObject((object)this.txtCodeInfo.Text.Trim());
                int num = (int)MessageBox.Show("复制成功，你现在可以直接粘贴到任何文本编辑器中了");
            }
            else
            {
                int num1 = (int)MessageBox.Show("文本框中没有内容，无法复制");
            }
        }

        private void label2_Click(object sender, EventArgs e)
        {
            FrmShowNumOrPassWord showNumOrPassWord = new FrmShowNumOrPassWord("pword");
            int num1 = (int)showNumOrPassWord.ShowDialog();
            if (!showNumOrPassWord.isOK)
                return;
            int num2 = (int)new FormZC().ShowDialog();
        }

        private void GetNowZC()
        {
            string path = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "\\sys.zk";
            if (!File.Exists(path))
            {
                this.lblzc.Text = "当前未注册！";
            }
            else
            {
                StreamReader streamReader = new StreamReader((Stream)File.Open(path, FileMode.Open), Encoding.GetEncoding("GB2312"));
                string end = streamReader.ReadToEnd();
                streamReader.Close();
                streamReader.Dispose();
                string str1 = PublicZC.Decode(end).Replace("\r\n", "\n");
                string[] strArray = str1.Split('\n');
                if (strArray[0] == Form4.GetSerialNumber() || strArray[0] == Form4.zc)
                {
                    string str2 = "无到期时间，";
                    string str3 = "未启用批量转换，";
                    string str31 = "未启用多合一转换。";
                    foreach (string str4 in strArray)
                    {
                        if (str4.StartsWith("datetime"))
                        {
                            str2 = "到期时间为：" + str4.Split(':')[1] + ",";
                            break;
                        }
                    }
                    if (str1.Contains("cbPL"))
                        str3 = "已启用批量转换，";
                    if (str1.Contains("cbDHY"))
                        str31 = "已启用多合一转换。";
                    
                  this.lblzc.Text = str2 + str3+ str31;
                }
                else
                    this.lblzc.Text = "当前未注册！";
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && this.components != null)
                this.components.Dispose();
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.label3 = new Label();
            this.txtCodeInfo = new TextBox();
            this.SelectFile = new Button();
            this.label1 = new Label();
            this.txtZCFilePath = new TextBox();
            this.btnUpdateCus = new Button();
            this.label2 = new Label();
            this.label4 = new Label();
            this.lblzc = new Label();
            this.label5 = new Label();
            this.SuspendLayout();
            this.label3.AutoSize = true;
            this.label3.Location = new Point(32, 41);
            this.label3.Name = "label3";
            this.label3.Size = new Size(67, 15);
            this.label3.TabIndex = 29;
            this.label3.Text = "机器码：";
            this.txtCodeInfo.Location = new Point(105, 37);
            this.txtCodeInfo.Name = "txtCodeInfo";
            this.txtCodeInfo.ReadOnly = true;
            this.txtCodeInfo.Size = new Size(519, 25);
            this.txtCodeInfo.TabIndex = 30;
            this.txtCodeInfo.DoubleClick += new EventHandler(this.txtCodeInfo_DoubleClick);
            this.SelectFile.Location = new Point(637, 101);
            this.SelectFile.Name = "SelectFile";
            this.SelectFile.Size = new Size(75, 29);
            this.SelectFile.TabIndex = 31;
            this.SelectFile.Text = "选择";
            this.SelectFile.UseVisualStyleBackColor = true;
            this.SelectFile.Click += new EventHandler(this.SelectFile_Click);
            this.label1.AutoSize = true;
            this.label1.Location = new Point(17, 107);
            this.label1.Name = "label1";
            this.label1.Size = new Size(82, 15);
            this.label1.TabIndex = 32;
            this.label1.Text = "注册文件：";
            this.txtZCFilePath.Location = new Point(105, 104);
            this.txtZCFilePath.Name = "txtZCFilePath";
            this.txtZCFilePath.ReadOnly = true;
            this.txtZCFilePath.Size = new Size(519, 25);
            this.txtZCFilePath.TabIndex = 33;
            this.btnUpdateCus.Location = new Point(720, 101);
            this.btnUpdateCus.Name = "btnUpdateCus";
            this.btnUpdateCus.Size = new Size(75, 29);
            this.btnUpdateCus.TabIndex = 34;
            this.btnUpdateCus.Text = "上传";
            this.btnUpdateCus.UseVisualStyleBackColor = true;
            this.btnUpdateCus.Click += new EventHandler(this.btnUpdateCus_Click);
            this.label2.AutoSize = true;
            this.label2.Font = new Font("宋体", 9f, FontStyle.Bold, GraphicsUnit.Point, (byte)134);
            this.label2.ForeColor = Color.DodgerBlue;
            this.label2.Location = new Point(726, 41);
            this.label2.Name = "label2";
            this.label2.Size = new Size(55, 15);
            this.label2.TabIndex = 35;
            this.label2.Text = "注册机";
            this.label2.Click += new EventHandler(this.label2_Click);
            this.label4.AutoSize = true;
            this.label4.Font = new Font("宋体", 9f, FontStyle.Regular, GraphicsUnit.Point, (byte)134);
            this.label4.ForeColor = Color.Red;
            this.label4.Location = new Point(630, 41);
            this.label4.Name = "label4";
            this.label4.Size = new Size(83, 15);
            this.label4.TabIndex = 36;
            this.label4.Text = "<-双击复制";
            this.label4.DoubleClick += new EventHandler(this.txtCodeInfo_DoubleClick);
            this.lblzc.AutoSize = true;
            this.lblzc.ForeColor = Color.Red;
            this.lblzc.Location = new Point(102, 164);
            this.lblzc.Name = "lblzc";
            this.lblzc.Size = new Size(55, 15);
            this.lblzc.TabIndex = 0;
            this.lblzc.Text = "label5";
            this.label5.AutoSize = true;
            this.label5.Location = new Point(17, 164);
            this.label5.Name = "label5";
            this.label5.Size = new Size(82, 15);
            this.label5.TabIndex = 37;
            this.label5.Text = "注册信息：";
            this.AutoScaleDimensions = new SizeF(8f, 15f);
            this.AutoScaleMode = AutoScaleMode.Font;
            this.ClientSize = new Size(940, 580);
            this.Controls.Add((Control)this.label5);
            this.Controls.Add((Control)this.lblzc);
            this.Controls.Add((Control)this.label4);
            this.Controls.Add((Control)this.label2);
            this.Controls.Add((Control)this.SelectFile);
            this.Controls.Add((Control)this.label1);
            this.Controls.Add((Control)this.txtZCFilePath);
            this.Controls.Add((Control)this.btnUpdateCus);
            this.Controls.Add((Control)this.label3);
            this.Controls.Add((Control)this.txtCodeInfo);
            this.MaximizeBox = false;
            this.Name = "Form4";
            this.StartPosition = FormStartPosition.CenterParent;
            this.Text = "Form4";
            this.Load += new EventHandler(this.Form4_Load);
            this.ResumeLayout(false);
            this.PerformLayout();
        }
    }
}
